package com.ftg.elvis.mapper;

import com.ftg.elvis.pojo.Apply;
import com.ftg.elvis.pojo.Brand;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface AdminApplyMapper {

	@Select("select * from apply where aname like concat('%', #{arg2}, '%') and astate = ifnull(#{arg3}, astate) limit #{arg0}, #{arg1}")
	List<Apply> showAll(int page, int limit, String aname, String astate);


	@Select("select count(*) from apply where aname like concat('%', #{arg0}, '%') and astate = ifnull(#{arg1}, astate)")
	int getCount(String aname, String astate);

	@Select("select * from apply where astate = ifnull(#{arg2}, astate) limit #{arg0}, #{arg1}")
	List<Apply> findByState(int page, int limit, String astate);

	@Select("select count(*) from apply where astate = ifnull(#{astate}, astate)")
	int getCountByState(String astate);

	@Update("update apply set astate = #{arg0} where aid = #{arg1}")
	int updateState(String astate, String aid);

	@Delete("delete from apply where aid = #{aid}")
	int delete(String aid);

	@Select("select * from apply where aid = #{aid}")
	Apply findByAid(String aid);

	/*
		brand.setBid(apply.getAid());
		brand.setBname(apply.getAname());
		brand.setBlogo(apply.getAlogo());
		brand.setBinfo(apply.getAinfo());
		brand.setBtel(apply.getPhone());
		brand.setBwebsite(apply.getAwebsite());
		brand.setBstate(apply.getAstate());
		brand.setUsername(apply.getUsername());
		brand.setEmail(apply.getAemail());

	 */


	@Insert("insert into brand(bid, bname, blogo, binfo, btel, bwebsite, bstate, username, email)" +
			" values(#{bid},#{bname},#{blogo},#{binfo},#{btel},#{bwebsite},#{bstate},#{username},#{email})")
	int saveApplyToBrand(Brand brand);
}
